import { splitToLength, BoolStrWithBoolen } from '../../Utils/common'

export function bodyCheck(data) {
  const {
    attr142,
    attr143,
    attr144,
    attr145,
    attr146,
    attr147,
    attr148,
    attr149,
  } = data
  let str = ''
  if (attr142) str += `体温${attr142}℃（R）`
  if (attr143) str += `，脉搏${attr143}次／min`
  if (attr144) str += `，呼吸${attr144}次／min`
  if (attr145) str += `，体重${attr145}kg`
  if (attr146) str += `，身高${attr146}cm`
  if (attr148 || attr147) str += `，血压 ${attr147}/${attr148}mmHg`
  if (attr149) str += `，经皮测血氧饱和度 ${attr149}%`
  str += '。'
  // const {
  //   attr150,
  //   attr151,
  //   attr152,
  //   attr153,
  //   attr154,
  //   attr155,
  //   attr156,
  //   attr158,
  //   attr237,
  //   attr238,
  // } = data
  // eslint-disable-next-line max-len
  // const sub1 = `发育状况${attr150}，营养状态${attr151}，神志${attr152}，精神状态${attr153}，${attr154to156Convert(
  //   attr154,
  //   attr155,
  //   attr156
  // )}，讲话${attr238}，脸色${attr158}，${attr237}发绀，`

  const sub1 = sub1Func(data)

  // const {
  //   attr159,
  //   attr160,
  //   attr161,
  //   attr162,
  //   attr163,
  //   attr164,
  //   attr165,
  //   attr166,
  //   attr167,
  //   attr168,
  //   attr169,
  //   attr170,
  //   attr171,
  //   attr172,
  // } = data
  // const sub2 = `${attr159}三凹症${
  //   attr160 ? ':' + attr160 : ''
  // }，${attr161}气短，体位: ${attr162}。眼部体征${attr163}异常${
  //   attr164 ? `(${attr164})` : ''
  // }，${attr165}荨麻疹(风团)${
  //   attr166 ? `(${attr166})` : ''
  // }，浅表淋巴结${attr167}${
  //   attr168 ? `(${attr168})` : ''
  // }，鼻粘膜${attr169}，${attr170to172(attr170, attr171, attr172)}`

  const sub2 = sub2Func(data)

  const {
    attr173,
    attr174,
    attr175,
    attr177,
    attr178,
    attr179,
    attr180,
    attr181,
    attr182,
    attr183,
    attr176,
  } = data
  // const sub3 = `${attr173to175Convert(
  //   attr173,
  //   attr174,
  //   attr175
  // )}咽部${attr176}，${attr177to179Convert(
  //   attr177,
  //   attr178,
  //   attr179
  // )}${attr180}表面分泌物，${attr181}咽后壁滤泡增生，${attr182}鼻后孔滴漏。`

  const sub3 = sub3Func(data)
  // const {
  //   attr184,
  //   attr185,
  //   attr186,
  //   attr187,
  //   attr188,
  //   attr189 = '',
  //   attr190 = '',
  //   attr191,
  //   attr192,
  //   attr193,
  //   attr194,
  //   attr195,
  //   attr196,
  //   attr197,
  //   attr199,
  //   attr198,
  // } = data
  // let sub4 = `呼吸运动双侧${attr183}，节律${attr184}齐。${attr185to186Convert(
  //   attr185,
  //   attr186
  // )}，听诊呼吸音${attr187}，${attr188}${attr190}湿啰音${
  //   attr189 ? `(${attr189})` : ''
  // }，${attr191to192Convert(attr191, attr192, attr193)}${
  //   attr194 ? '，脉率' + attr194 : ''
  // }，${attr195to197Convert(attr195, attr196, attr197)}，`

  // if (attr198) sub4 += `${attr198}痰鸣音。`
  // if (attr199) sub4 += `肺部其他体征：${attr199}。`
  const sub4 = sub4Func(data)
  str = str + sub1 + sub2 + sub3 + sub4
  return str
}
function sub4Func(data) {
  const {
    attr183,
    attr184,
    attr185,
    attr186,
    attr187,
    attr188,
    attr189 = '',
    attr190 = '',
    attr191,
    attr192,
    attr193,
    attr194,
    attr195,
    attr196,
    attr197,
    attr199,
    attr198,
    hasThroatSounds,
  } = data
  // let sub44 = `呼吸运动双侧${attr183}，节律${attr184}齐。${attr185to186Convert(
  //   attr185,
  //   attr186
  // )}，听诊呼吸音${attr187}，${attr188}${attr190}湿啰音${
  //   attr189 ? `(${attr189})` : ''
  // }，${attr191to192Convert(attr191, attr192, attr193)}${
  //   attr194 ? '，脉率' + attr194 : ''
  // }，${attr195to197Convert(attr195, attr196, attr197)}，`

  let sub4 = ''
  if (attr183) sub4 += `呼吸运动双侧${attr183}，`
  if (attr184) sub4 += `节律${attr184}齐。`
  sub4 += `${attr185to186Convert(attr185, attr186)}，`
  if (attr187) sub4 += `听诊呼吸音${attr187}，`
  if (attr188) {
    sub4 += `${attr188}${attr190 ? attr190 : ''}湿啰音${
      attr189 ? `(${attr189})` : ''
    }，`
  }
  sub4 += `${attr191to192Convert(attr191, attr192, attr193)},`
  sub4 += ` ${attr194 ? '脉率' + attr194 : ''}，`
  sub4 += `${attr195to197Convert(attr195, attr196, attr197)}，`

  if (attr198) sub4 += `${attr198}痰鸣音，`
  if (hasThroatSounds) sub4 += `${hasThroatSounds}喉鸣音。`
  if (attr199) sub4 += `肺部其他体征：${attr199}。`
  return sub4
}

function sub3Func(data) {
  const {
    attr173,
    attr174,
    attr175,
    attr177,
    attr178,
    attr179,
    attr180,
    attr181,
    attr182,
    attr176,
  } = data

  let sub3 = ''
  sub3 += `${attr173to175Convert(attr173, attr174, attr175)}，`
  if (attr176) sub3 += `咽部${attr176}，`
  sub3 += `${attr177to179Convert(attr177, attr178, attr179)}`
  if (attr180) sub3 += `${attr180}表面分泌物，`
  if (attr181) sub3 += `${attr181}咽后壁滤泡增生，`
  if (attr182) sub3 += `${attr182}鼻后孔滴漏。`
  return sub3
}

function sub2Func(data) {
  const {
    attr159,
    attr160,
    attr161,
    attr162,
    attr163,
    attr164,
    attr165,
    attr166,
    attr167,
    attr168,
    attr169,
    attr170,
    attr171,
    attr172,
  } = data

  let sub2 = ''
  if (attr159) sub2 += `${attr159}三凹症${attr160 ? ':' + attr160 : ''}，`
  if (attr161) sub2 += `${attr161}气短，`
  if (attr162) sub2 += `体位: ${attr162}。`
  if (attr163)
    sub2 += `眼部体征${attr163}异常${attr164 ? `(${attr164})` : ''}，`
  if (attr165)
    sub2 += `${attr165}荨麻疹(风团)${attr166 ? `(${attr166})` : ''}，`
  if (attr167) sub2 += `浅表淋巴结${attr167}${attr168 ? `(${attr168})` : ''}，`
  if (attr169) sub2 += `鼻粘膜${attr169}，`
  sub2 += `${attr170to172(attr170, attr171, attr172)}`
  return sub2
}

function sub1Func(data) {
  const {
    attr150,
    attr151,
    attr152,
    attr153,
    attr154,
    attr155,
    attr156,
    attr158,
    attr237,
    attr238,
  } = data

  // eslint-disable-next-line max-len
  // const sub11 = `发育状况${attr150}，营养状态${attr151}，神志${attr152}，精神状态${attr153}，${attr154to156Convert(
  //   attr154,
  //   attr155,
  //   attr156
  // )}，讲话${attr238}，脸色${attr158}，${attr237}发绀，`

  let sub1 = ''
  if (attr150) sub1 += `发育状况${attr150}，`
  if (attr151) sub1 += `营养状态${attr151}，`
  if (attr152) sub1 += `神志${attr152}，`
  if (attr153) sub1 += `精神状态${attr153}，`
  sub1 += `${attr154to156Convert(attr154, attr155, attr156)}，`
  if (attr238) sub1 += `讲话${attr238}，`
  if (attr158) sub1 += `脸色${attr158}，`
  if (attr237) sub1 += `${attr237}发绀，`
  return sub1
}

function attr170to172(attr170, attr171, attr172) {
  if (BoolStrWithBoolen(attr170) && attr171 && attr172) {
    return `有鼻腔分泌物(${attr171},${attr172})`
  } else if (BoolStrWithBoolen(attr170) && attr171) {
    return `有鼻腔分泌物(${attr171})`
  } else if (BoolStrWithBoolen(attr170) && attr172) {
    return `有鼻腔分泌物(${attr172})`
  } else if (BoolStrWithBoolen(attr170) === false) {
    return `无鼻腔分泌物`
  } else if (BoolStrWithBoolen(attr170) === true) {
    return `有鼻腔分泌物`
  }
  return ''
}
function attr195to197Convert(attr195, attr196, attr197) {
  if (BoolStrWithBoolen(attr195) === false) {
    return '未闻鼾音'
  } else if (
    BoolStrWithBoolen(attr195) &&
    attr196 &&
    splitToLength(attr196, 2)
  ) {
    return `闻双相鼾音${attr197 ? `(${attr197})` : ''}`
  } else if (BoolStrWithBoolen(attr195)) {
    return `${attr196 ? attr196 + '鼾音' : ''}${attr197 ? `(${attr197})` : ''}`
  }
  return ''
}
function attr191to192Convert(attr191, attr192, attr193) {
  if (BoolStrWithBoolen(attr191) === false) {
    return '未闻哮鸣音'
  } else if (BoolStrWithBoolen(attr191) && (attr192 || attr193)) {
    const tmp = `闻${attr192 ? attr192 : ''}哮鸣音${
      attr193 ? ',' + `(${attr193})` : ''
    }`
    return tmp
  } else if (BoolStrWithBoolen(attr191)) {
    return '闻哮鸣音'
  }
  return ''
}
function attr185to186Convert(attr185, attr186) {
  const b = BoolStrWithBoolen(attr185)
  if (b && attr186) {
    return attr186
  } else if (b) {
    return '呼吸困难'
  } else if (b === false) {
    return '呼吸无困难'
  }
  return ''
}
function attr177to179Convert(attr177, attr178, attr179) {
  if (BoolStrWithBoolen(attr177) && attr178 && attr179) {
    return `扁桃体肿大（左侧${attr178}度，右侧${attr179}度），`
  } else if (BoolStrWithBoolen(attr177) && attr178) {
    return `扁桃体肿大（左侧${attr178}度），`
  } else if (BoolStrWithBoolen(attr177) && attr179) {
    return `扁桃体肿大（右侧${attr179}度），`
  } else if (BoolStrWithBoolen(attr177)) {
    return `扁桃体肿大，`
  } else if (!BoolStrWithBoolen(attr177)) {
    return `扁桃体无肿大，`
  }
  return ''
}

function attr173to175Convert(attr173, attr174, attr175) {
  // 下鼻甲肿胀,阻塞鼻腔左侧12右侧12
  if (BoolStrWithBoolen(attr173) && attr174 && attr175) {
    return `，下鼻甲有肿胀（阻塞鼻腔左侧${attr174}，右侧${attr175}），`
  } else if (BoolStrWithBoolen(attr173) && attr174) {
    return `，下鼻甲有肿胀（阻塞鼻腔左侧${attr174}），`
  } else if (BoolStrWithBoolen(attr173) && attr175) {
    return `，下鼻甲有肿胀（阻塞鼻腔右侧${attr175}），`
  } else if (BoolStrWithBoolen(attr173)) {
    return `，下鼻甲有肿胀，`
  } else if (!BoolStrWithBoolen(attr173)) {
    return `，下鼻甲无肿胀，`
  }
  return ``
}
function attr154to156Convert(attr154, attr155, attr156) {
  if (BoolStrWithBoolen(attr154)) {
    let str = '精神状态有改变'
    if (splitToLength(attr155, 4) && attr156) {
      str += `（焦虑${attr156 ? `(${attr156})` : ''},烦躁,嗜睡,意识不清）`
    } else if (splitToLength(attr155, 4) && !attr156) {
      str += `（焦虑,烦躁,嗜睡,意识不清）`
    } else if (attr155 && attr155.includes('焦虑')) {
      // TODO 怎么抽出这个焦虑 把156拼上去
      str += `（焦虑${attr156 ? `(${attr156})` : ''}`
      if (attr155.includes('烦躁')) str += ',烦躁'
      if (attr155.includes('嗜睡')) str += ',嗜睡'
      if (attr155.includes('意识不清')) str += ',意识不清'
      str += ')'
    } else if (attr155 && !attr155.includes('焦虑')) {
      str += '(' + attr155 + ')'
    }
    return str
  } else if (BoolStrWithBoolen(attr154) === false) {
    return '精神状态没有改变'
  }
  return ''
}
